import requests
import logging


# 创建登录模块
class LoginApi:
    # 登录接口
    def login(self, json_dict=None):
        url = "http://ihrm-test.itheima.net/api/sys/login"
        res = requests.post(url=url, json=json_dict)
        # 获取字典类型的响应体数据
        res_dict = res.json()
        # logging.info("登录接口返回的响应体数据:{}".format(res_dict))
        return res

    # 获取token
    def get_token(self, json_dict):
        res = self.login(json_dict)
        res_token = res.json().get("data")
        logging.info("获取的token:{}".format(res_token))

        return "Bearer" + " " + res_token

# 实例化方法验证token
# if __name__ == '__main__':
#     json_dict = {"mobile": "13800000001", "password": "123456"}
#     print(LoginApi().get_token(json_dict))
